<!--
  用户管理-企业用户-简历管理
 -->
<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      ref="queryParams"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="性别" prop="sex">
        <el-select
          v-model="queryParams.sex"
          placeholder="请选择性别"
          clearable
          size="small"
        >
          <el-option label="不限" value="" />
          <el-option label="男" value="男" />
          <el-option label="女" value="女" />
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.startDate"
          type="number"
          style="width: 120px"
          placeholder="岁"
        />
        至
        <el-input
          v-model="queryParams.endDate"
          type="number"
          style="width: 120px"
          placeholder="岁"
        />
      </el-form-item>
      <el-form-item label="居住地" prop="liveCity">
        <el-cascader
          v-model="queryParams.liveCity"
          :show-all-levels="false"
          :options="provinceAndCityData"
          :props="{ value: 'label' }"
          placeholder="请选择城市"
        />
      </el-form-item>
      <!-- <el-form-item label-width="120px" label="学校/学历/专业" prop="educationalExperience">
        <el-input
          v-model="queryParams.educationalExperience"
          placeholder="支持模糊匹配"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="技能" prop="specialtyAbility">
        <el-input
          v-model="queryParams.specialtyAbility"
          placeholder="请输入技能"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="语种" prop="languageAbility">
        <el-input
          v-model="queryParams.languageAbility"
          placeholder="请输入语种"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课程" prop="courses">
        <el-input
          v-model="queryParams.courses"
          placeholder="请输入课程"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
        >搜索</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table ref="resumeTable" v-loading="loading" :data="list" :row-key="getRowKey" @selection-change="handleChange">
      <el-table-column
        type="selection"
        width="55"
        :reserve-selection="true"
      />
      <el-table-column label="序号" type="index" />
      <el-table-column label="学生姓名" align="center" prop="studentName" />
      <el-table-column label="手机号" align="center" prop="phoneNumber" />
      <el-table-column label="学校" align="center" prop="schoolName" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="所学专业" align="center" prop="major" />
      <el-table-column label="居住地" align="center" prop="liveCity" />
      <el-table-column label="学历" align="center" prop="education" />
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page-sizes="[10, 20, 30, 50, 100, 200, 500]"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getUserResume } from '@/api/school-admin-api/userManage/student/index.js'
import { deepClone } from '@/utils/index'
import moment from 'moment'
import { provinceAndCityData } from '../../../../utils/frontDataDict'
export default {
  name: 'ResumeList',
  components: {
  },
  data() {
    return {
      provinceAndCityData,
      // 遮罩层
      loading: true,
      // 待审核-总条数
      total: 0,
      // 企业管理列表
      list: [],
      AllData: [],
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        sex: '', // 性别
        startDate: '', // 年龄起始日期
        endDate: '', // 年龄结束日期
        liveCity: [], // 居住地
        languageAbility: '', // 语种
        courses: '', // 已修课程
        specialtyAbility: '', // 专业技能
        educationalExperience: '' // 学校/学历/专业 模糊匹配
      },
      selectSdudentList: []
    }
  },
  created() {
    this.getAllData()
  },
  methods: {
    getRowKey(row) {
      return 'resume' + row.studentId
    },
    // 多选
    handleChange(val) {
      console.log('选中简历>>>', val)
      this.selectSdudentList = [...val]
      this.$emit('selectChange', [...this.selectSdudentList])
    },
    deleteSelectionItem(item) {
      this.$refs.resumeTable.toggleRowSelection(item, false)
      console.log('删除选中>>>', item)
    },
    // 简历列表
    getAllData() {
      this.loading = true
      // 处理查询参数
      const params = JSON.parse(JSON.stringify(this.queryParams))
      for (const key in params) {
        if (params[key] === '' || params[key] === null) {
          delete params[key]
        }
      }
      if (this.queryParams.startDate) {
        const now = new Date().getTime()
        params.endDate = moment(now - 1000 * 60 * 60 * 24 * 365 * this.queryParams.startDate).format('yyyy-MM-DD')
      }
      if (this.queryParams.endDate) {
        const now = new Date().getTime()
        params.startDate = moment(now - 1000 * 60 * 60 * 24 * 365 * this.queryParams.endDate).format('yyyy-MM-DD')
      }
      if (Array.isArray(params.liveCity) && params.liveCity.length === 2) {
        params.liveCity = params.liveCity[1]
      } else {
        delete params.liveCity
      }
      params.pageSize = 99999
      // 执行查询
      getUserResume(params).then((res) => {
        const list = deepClone(res.data.list).map((item) => {
          if (
            Array.isArray(item.educationalExperience) &&
            item.educationalExperience.length
          ) {
            const educate = ['大专', '本科', '硕士', '博士']
            educate.map((iten) => {
              const matchEducate = item.educationalExperience.find(
                (single) => single.educationalBackground.indexOf(iten) > -1
              )
              if (matchEducate) {
                item.schoolName = matchEducate.schoolName // 学校名称
                item.major = matchEducate.major // 专业
                item.education = iten // 学历
              }
            })
          } else {
            item.schoolName = '--' // 学校名称
            item.major = '--' // 专业
            item.education = '--' // 学历
          }
          return item
        })
        this.AllData = []
        list.map(item => {
          const hasOne = this.AllData.find(jj => item.studentId === jj.studentId)
          if (!hasOne) {
            this.AllData.push(item)
          }
        })
        this.loading = false
        this.getList()
      })
    },
    getList() {
      const { pageNo, pageSize } = this.queryParams
      this.list = this.AllData.slice(pageSize * (pageNo - 1), pageSize * pageNo)
      this.total = this.AllData.length
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getAllData()
    },
    // 重制搜索条件
    resetQuery() {
      this.selectSdudentList = []
      this.resetForm('queryParams')
      this.queryParams.startDate = ''
      this.queryParams.endDate = ''
      this.$refs.resumeTable.clearSelection()
      this.handleQuery()
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/assets/styles/vars.scss";
</style>
